<template>
  <div class="AddWorkflow">
    <div class="top-box">
      <div class="left-box">
        <div class="color-box"></div>
        <p v-if="id==0">新建工作流</p>
        <p v-else>工作流详情</p>
      </div>
      <el-button class="right-box" type="info" icon="el-icon-back" @click="Return()">返回</el-button>
    </div>
    <div class="content" v-if="id==0">
      <div class="center">
        <div class="form_body">
          <table
            class="table"
            border="1"
            style="border-color:#f5f5f5;width:100%;table-layout:fixed;text-align:center"
          >
            <tr style="height:60px;">
              <td style="width:20%">合作项目</td>
              <td style="width:80%;text-align:left;padding-left:20px">
                <el-input class="el" v-model="formInline.ProName"></el-input>
              </td>
            </tr>
            <tr>
              <td>合作内容</td>
              <td style="text-align:left;padding-left:20px">
                <el-input
                  placeholder="请输入合作内容"
                  :rows="10"
                  type="textarea"
                  v-model="formInline.Main"
                  style="width:90%;height:250px;padding-top:20px;"
                ></el-input>
              </td>
            </tr>
            <tr style="height:60px;">
              <td style="width:20%">完成日期</td>
              <td style="width:80%;text-align:left;padding-left:20px">
                <el-date-picker
                  class="el"
                  v-model="formInline.FinshTime"
                  type="date"
                  placeholder="选择日期"
                ></el-date-picker>
              </td>
            </tr>

            <tr style="height:60px;">
              <td>合作对象</td>
              <td style="text-align:left;padding-left:20px">
                <el-select class="el" v-model="formInline.Partners" value-key="key">
                  <el-option
                    v-for="item in company"
                    :key="item.Id"
                    :label="item.Name"
                    :value="item.Id"
                  ></el-option>
                </el-select>
              </td>
            </tr>
            <tr style="height:60px;">
              <td>合作金额（元）</td>
              <td style="text-align:left;padding-left:20px">
                <el-input
                  v-model="formInline.Price"
                  class="el"
                  oninput="value=value.replace(/[^\d.]/g,'')"
                ></el-input>元
              </td>
            </tr>
          </table>
        </div>
      </div>
      <div class="end" v-show="shows==0">
        <el-button type="primary" @click="add" v-if="id==0">确定</el-button>
        <el-button type="primary" @click="shenhe" v-else>审核</el-button>
        <el-button type="info" @click="Return">返回</el-button>
      </div>
    </div>

    <div class="content" v-else>
      <div class="center">
        <div class="form_body">
          <table class="table" border="1" style="border-color:#e7e7e7;;width:100%;text-align:center">
            <tr style="height:60px;">
              <td style="width:20%">合作项目</td>
              <td style="width:80%;text-align:left;padding-left:20px">{{formInline.ProName}}</td>
            </tr>
            <tr style="min-height:60px;">
              <td style="width:20%">合作内容</td>
              <td
                style="width:80%;text-align:left;padding:20px;line-height:25px;"
              >{{formInline.Main}}</td>
            </tr>
            <tr style="height:60px;">
              <td style="width:20%">完成日期</td>
              <td style="width:80%;text-align:left;padding-left:20px">{{formInline.FinshTime}}</td>
            </tr>

            <tr style="height:60px;">
              <td>合作对象</td>
              <td style="text-align:left;padding-left:20px">{{formInline.Partners}}</td>
            </tr>
            <tr style="height:60px;">
              <td>合作金额（元）</td>
              <td style="text-align:left;padding-left:20px">{{formInline.Price}}元</td>
            </tr>
          </table>
          <table class="tablenew" v-if="rejectList.length>0" style="border-color:#f5f5f5;width:100%;text-align:center">
            <tr v-for="item in rejectList" :key="item.id">
              <td style="width:149px;font-weight:700;">驳回时间</td>
              <td style="width:150px;">{{item.Time}}</td>
              <td style="width:150px;font-weight:700;">驳回原因</td>
              <td style="padding:20px;line-height:24px;">{{item.Main}}</td>
              <td style="width:150px;font-weight:700;">审批人</td>
              <td style="width:150px;">{{item.Name}}</td>
            </tr>
          </table>
        </div>
      </div>
      <div class="end" v-show="shows==0" v-if="id==0">
        <el-button type="primary" @click="add">确定</el-button>
        <el-button type="info" @click="Return">返回</el-button>
      </div>
      <div class="end" v-show="shows==0" v-else>
        <el-button type="primary" @click="caozuo(2)">通过</el-button>
        <el-button type="primary" @click="buohui">驳回</el-button>
      </div>
    </div>
    <!-- 驳回弹框 -->
    <el-dialog title="驳回" :append-to-body="true" :visible.sync="dialogVisibles" width="30%">
      <div class="color_box"></div>
      <el-input
        type="textarea"
        :autosize="{ minRows: 2, maxRows: 4}"
        placeholder="请输入内容"
        v-model="main"
      ></el-input>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" type="primary" @click="caozuo(3)">确定</el-button>
        <el-button size="small" type="info" @click="dialogVisibles = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import axios from "axios";
export default {
  data () {
    return {
      dialogVisibles: false,
      main: "",
      company: [{ Name: "", Id: 0 }],
      formInline: { ProName: "", Main: "", FinshTime: "", Partners: "", Price: "", Creater: "", },
      creater: 0,
      Mark: 0,
      shows: 1,
      id: 0,
      rejectList: []
    };
  },
  created () {
    this.formInline.Creater = JSON.parse(localStorage.getItem("message")).Id;
    this.id = this.$route.query.e;
    this.shows = this.$route.query.shows;
    if (this.id > 0) { this.getdetail(); }
    this.getCompany();
  },
  methods: {
    buohui () { this.dialogVisibles = true; },
    caozuo (e) {
      if (this.Mark == 0) {
        if (e == 3) { if (this.main == "") { this.$message.error("驳回事由非空"); return } }
        var obj = { itemId: this.id, main: this.main, state: e, creater: this.formInline.Creater };
        var objs = JSON.stringify(obj); let the = { index: 1, jsondata: objs };
        this.Mark = 1;
        axios.post("/apis/CEOManage.asmx/Examine", the).then(({ data }) => {
          var list = JSON.parse(data.d);
          if (list.flag == true) {
            this.$message.success(list.tip);
            setTimeout(() => {
              window.history.go(-1);
            }, 500);          }
          else { this.$message.error(list.tip); }
        })
      }
    },
    getdetail () {
      let obj = { id: this.id };
      var objs = JSON.stringify(obj);
      let the = { index: 7, jsondata: objs }

      console.log(objs)
      axios.post("/apis/CEOManage.asmx/GetData", the).then(({ data }) => {
        var list = JSON.parse(data.d);
        console.log(list)
        this.formInline = list.basemess;
        this.rejectList = list.rejectList;
      });
    },
    getCompany () {
      let obj = { creater: this.formInline.Creater };
      var objs = JSON.stringify(obj);
      let the = { index: 16, jsondata: objs }
      axios.post("/apis/AdministrationManage.asmx/GetData", the).then(({ data }) => {
        var list = eval('(' + data.d + ')');
        this.company = list;
      });
    },
    add () {
      if (this.Mark == 0) {
        if (this.formInline.Partners == "") { this.$message.error("请选择合作公司"); return; }
        if (this.formInline.ProName == "") { this.$message.error("请填写项目名称"); return; }
        if (this.formInline.Main == "") { this.$message.error("请填写合作内容"); return; }
        if (this.formInline.FinshTime == "") { this.$message.error("请填写完成日期"); return; }
        if (this.formInline.Price == "") { this.$message.error("请填写合作金额"); return; }
        var objs = JSON.stringify(this.formInline); let the = { index: 3, jsondata: objs };
        this.Mark = 1;
        axios.post("/apis/CEOManage.asmx/Add", the).then(({ data }) => {
          var list = JSON.parse(data.d);
          if (list.flag == true) {
            this.$message.success(list.tip);
            setTimeout(() => {
              window.history.go(-1);
            }, 500);          }
          else { this.$message.error(list.tip); }
        });
      }
    },
    Return () {
      window.history.go(-1);
    }
  }
};
</script>

<style lang="scss" scoped>
@import '@/assets/scss/base.scss';
.top-box {
  width: 100%;
  height: 60px;
  overflow: hidden;
  margin-bottom: 10px;
}
.left-box {
  width: 100px;
  height: 40px;
  float: left;
  margin-top: 10px;
  overflow: hidden;
  margin-left: 1%;
}
.color-box {
  width: 5px;
  height: 20px;
  float: left;
  margin-top: 10px;
  background-color: $Header_color;
}
.left-box p {
  float: left;
  margin-left: 5px;
  line-height: 40px;
}
.right-box {
  float: right;
  margin-right: 2%;
  border-radius: 5px;
  margin-top: 15px;
}
.content {
  padding-left: 10px;
  padding-right: 10px;
}
.center {
  background-color: #fff;
  width: 100%;
  padding-top: 50px;
  padding-bottom: 20px;
  margin-bottom: 20px;
}
.demo-form-inline {
  margin-left: 30px;
  margin-bottom: 30px;
}
.end {
  text-align: center;
}
.kuang {
  padding-top: 30px;
  width: 70%;
  margin: 0 auto;
  // height: 300px;
  border: 1px solid #d3d4d4;
  margin-bottom: 20px;
}
.form_body {
  width: 70%;
  // border: 1px solid #f5f5f5;
  margin-left: 15%;
}
.table {
  border: 0px solid #e7e7e7;
  border-top: 0.5px solid #e7e7e7;
  // margin-bottom: 20px;
}
.tablenew tr td {
  border: 1px solid #e7e7e7;
  border-top: 0.5px;
  text-align: center;
}
.el {
  width: 90%;
}
</style>